<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include '../../connection/connection.php';
include "../../value/value_kr.php";
$monitor = $_REQUEST['monitor'];
$monitorname=$_REQUEST['monitorname'];
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=edge" />
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<link href="../../popup-window.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../popup-window.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	ScrollTable();
	
});
function MyResize(){
	ScrollTable();
}

function ScrollTable(){
	wid = $("table#tablebody2").parent().css('width');
	wid = wid.slice(0,-2)-17;
	$("table#tablebody2").css("width", wid);
	$("table#tablebodyheader").css("width", wid);
	$('table#tablebody2').parent().scrollTop(0);
	OnTRCSS();
}
function OnTRCSS(){
	$("table.tbchung tr:even").each(function(){
		$(this).css("background-color","#eff3fa");
	});
}
</script>
<script type="text/javascript">
$(function() {
	 var checkexistus = '<?=$_SESSION['iduser']?>';
	if(checkexistus==''){
		admin_logout();
		}
});
function admin_logout(){
	window.location="../../view_logout.php?changepage=admin";
}
function onclickSearch(){
	window.location = "../../search/searchcarnums.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>";
}
function onclickView(){
	window.location = "../../index.php?viewaction=none";
}
//check select all
function checkSelectAll(bx){
	var cbs = document.getElementsByTagName('input');
	  for(var i=0; i < cbs.length; i++) {
	    if(cbs[i].type == 'checkbox') {
	      cbs[i].checked = bx.checked;
	    }
	  }
}
function checkSelectAll(){
	if($("#checkall").is(':checked')){
		$('.checkCamera:checkbox').attr('checked',true);
	}else{
		$('.checkCamera:checkbox').attr('checked',false);
	}
}
function onclickrecordcheck(id){
	var gt=document.getElementById(""+id).checked;
	document.getElementById(id).checked = !gt;
	
}
function processDeleteCarCrimeUser(){
	var winH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	   var elements = document.getElementById("mpform").elements;
	   var ids = new Array(); 
	   for(var i=0; i< elements.length;i++){
	      if(elements[i].type == 'checkbox' && elements[i].checked){
		      ids[i] = elements[i].value;
	    
	 	 $.ajax({url:"process-delete-car-crime-user.php?idcarnum="+ids+"&winH="+winH,success:function(result){
			 document.getElementById("idtablecontentcarcrimeuser").innerHTML=result;
			 ScrollTable();
	 	}
		});
	      }else{
	    	  $('#checkall').attr('checked', false);
		      }
	}
	
}
function reset(){
	document.getElementById('txtcarcrime').value="";
	document.getElementById('txtnote').value="";
}
function insert_carcrime_userinput(userid){
	var carcrime = $('#txtcarcrime').val();
	var note = $('#txtnote').val();

	if(document.getElementById('txtcarcrime').value.length==0){
		alert("Crime's car name  is not null");
		return false;
	}
	$.ajax({url: "check_exist_carnumbercrime.php?carcrime="+carcrime,success: function(result){
   		//alert(result);
   		document.getElementById('dvidcarcrimehidden').innerHTML = result;
		var results = document.getElementById('idcarcrimehidden').value;
   		if(results=='no'){
	   		alert("crime's car number already existed");
   		}else{
   			var winH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
   			
			$.ajax({url:"insert-carcrime-userinput.php?carcrime="+carcrime+"&note="+note+"&userid="+userid+"&winH="+winH,success:function(result){
					document.getElementById('idtablecontentcarcrimeuser').innerHTML = result;
					alert('<?=$l_alertinsertsuccessful?>');
					 ScrollTable();
					reset();
				}
			});
   		}
      }
	});
}
function sortAndPagingCarCrimeUser(string,flagDesc){
	var winH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	$.ajax({url:"sortAndPagingCarCrimeUser.php?string="+string+"&flagDesc="+flagDesc+"&winH="+winH,success:function(result){
		var expr = new RegExp('>[ \t\r\n\v\f]*<', 'g');
		var response_html_fixed = result.replace(expr, '><');
		document.getElementById('idtablecontentcarcrimeuser').innerHTML = response_html_fixed;
		 ScrollTable();
		}
	});
}
function loadAdll_carcrimeUser(){
	$.ajax({url:"loadAll-carcrime-user.php",success:function(result){
		document.getElementById('idtablecontentcarcrimeuser').innerHTML = result;
		 ScrollTable();
		}
	});
}
function loadpos(){
	var winHf = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	$("#divscroll").css("height", parseInt(winHf - 270));
}
function loadContentCarcrimeByuser(){
	var winH =window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 
	$.ajax({url:"ajax_load_content_carcrimebyuser.php?winH="+winH,success:function(result){
		document.getElementById('idtablecontentcarcrimeuser').innerHTML = result;
		 ScrollTable();
		}
	});
}
</script>
</head>

<?php include 'show_function_popup_carcrime.php';?>
<body onresize="MyResize();" onload="loadpos();loadContentCarcrimeByuser();load_popup_carCrime();">
<p id="maylya" ><input type="hidden"  id="mayly" name="mayly" /></p>
<div id="dvidcarcrimehidden" style="display: none;"><input type="hidden" id="idcarcrimehidden"></div>
    <div id="menu" style="text-align: center;">
    	<ul class="amenu">
        	<li><a onclick="onclickSearch();"><input class="csssearch" type="button"/></a></li>
            <li style="background:#1e7bbd"><a href=""><input class="cssadminchoose" type="button"/></a></li>
            <li style="width: 215px;"><a onclick="onclickView();"><input class="cssview" type="button"/></a>
	            <select class="seltopadmin"  disabled="disabled">
	            	<option><?php echo $monitorname;?></option>
	            </select>
            </li>
            <li><a onclick="admin_logout()" style="cursor:pointer" ><input class="csslogout" type="button"/></a></li>
        </ul>
         <div class="clear"></div>
    </div>
    <div id="submenu">
    	<ul class="asubmenu">
        	<li><a href="../content-monitor-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_monitor?></a></li>
            <li><a href="../camera/content-camera-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_camera?></a></li>
           <li><a href="#" style="background:#034776; border-radius:6px"><?php echo $l_carcrimeuser?></a></li>
            <li><a href="../car-crime/content-car-crime-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_carcrime?></a></li>
            <li><a href="../PC/content-PC-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>">PC</a></li>
            <li><a href="../user/content-user-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>" ><?php echo $l_user?></a></li>
        </ul>
        <div class="clear"></div>
    </div>
    <div class="main">
   	 <table cellpadding="0" cellspacing="0" border="0" width="55%" class="tbm1">
            <tr>
                <td><?php echo $l_carnum?></td>
                <td><input type="text" class="intext" style="width:250px;padding-left: 5px;line-height: 26px;text-align: left;" id="txtcarcrime" name="txtcarcrime"/></td>
                <td>Note</td>
                <td><input type="text" class="intext" style="width:250px;padding-left: 5px;line-height: 26px;text-align: left;" id="txtnote" name="txtnote"/></td>
                <td><input type="button" class="inbtn" style="width: 65px;" value="Add" onclick="insert_carcrime_userinput('<?=$_SESSION['iduser']?>');"/></td>
            </tr>            
        </table>
        <form  id="mpform" name="mpform">
        <div style="color:white; margin:10px 0"><input type="checkbox" id="checkall" name="checkall" onclick="checkSelectAll()"/><?php echo $l_selectall?></div>
         <div class="divtheader" style="min-width:624px;">
            	<table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebodyheader">
            		<thead>
			            <tr>
			                <th style="width:5%"><input type="button" value="<?php echo $l_delete?>" class="indelete" 
			                 	onclick="if(confirm('<?=$l_areyousure?>')){ processDeleteCarCrimeUser();return true;}else{return false;}"/></th>
			                <th style="width: 5%">No</th>
			                <th style="width:25%"><a onclick="sortAndPagingCarCrimeUser('c.carnum',1)" style="cursor: pointer;color: #027acc"><?php echo $l_carnum?></a></th>
			                <th style="width:25%"><a onclick="sortAndPagingCarCrimeUser('c.regNote',1)" style="cursor: pointer;color: #027acc">Note</a></th>
			                <th style="width:20%"><a onclick="sortAndPagingCarCrimeUser('c.regDatetime',1)" style="cursor: pointer;color: #027acc">Date time</a></th>
			                <th style="width:20%" class="last" ><a onclick="sortAndPagingCarCrimeUser('u.szUser',1)" style="cursor: pointer;color: #027acc">User</a></th>
			            </tr>
	            </thead>
            	</table>
           </div>
        <div  id="idtablecontentcarcrimeuser">
          <div id="divscroll" style="overflow:scroll;overflow-x: hidden; width:100%;background-color: #ffffff">
	        <table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebody2">
	            <tbody>
	            
	            </tbody>              
	        </table>
	        </div>
	        <div>
	        	<table>
	        		<tr>
						<td class="rf-dt-ftr-carcrime-user" style="text-align: left;padding-top: 15px; " colspan="7">
						<label style="color: white;padding-left: 15px;">  <?php echo $l_totalrecord?></label>
						</td>
						
					</tr>	
	        	</table>
	        </div>
        </div>
        </form>
    </div>
    <?php include 'show_content_popup_carcrime.php';?>
</body>
</html>
 <?php mysql_close($connection);?>